package com.aba.hos.dao.impl;




import com.aba.hos.admin.Admin;
import com.aba.hos.dao.AdminDao;
import com.aba.hos.dao.PatDao;
import com.aba.hos.doc.entity.PatWord;
import com.aba.hos.doc.entity.Patient;
import com.aba.hos.utils.BaseDao;

import java.sql.SQLException;
import java.util.List;

public class PatDaoImpl extends BaseDao<Patient> implements PatDao {

    
    @Override
    public int addPat(Patient pat) throws SQLException {
        return this.update("INSERT INTO hos.patient (docId, name, age, gender, diagnosis, bedNumber, admissionDate, adminId) VALUES (?, ?, ?, ?, ?, ?, ?, ?);",
                pat.getDocId(),pat.getName(),pat.getAge(),pat.getGender(),pat.getDiagnosis(),pat.getBedNumber(),pat.getAdmissionDate(),pat.getAdminId()
        );
    }


    @Override
    public int updatePatName(Admin a) throws SQLException {
        return this.update("update hos.patient set name=? where id = ?",
                a.getName(),a.getId()
        );
    }

    public int updatePatDoc(String id,String docName) throws SQLException {
        return this.update("update hos.patient set docId=? where id = ?",
                docName,id
        );
    }

    @Override
    public int updatePatStatus(String id) throws SQLException {
        return this.update("update hos.patient set isRunHospital=1 where id = ?",
                id
        );
    }


    @Override
    public Patient queryPatById(Integer id) throws SQLException {
        return this.getBean("select id, docId, name, age, gender, diagnosis, bedNumber, admissionDate, adminId from hos.patient where id = ?" , id);
    }

    @Override
    public int updatePatWordDiagnosis(Patient p) throws SQLException {
        return this.update("update hos.patient set diagnosis=? where id = ?",
                p.getDiagnosis(),p.getId()
        );
    }

    @Override
    public Patient queryPatByName(String name) throws SQLException {
        return this.getBean("select id, docId, name, age, gender, diagnosis, bedNumber, admissionDate, adminId from hos.patient where name = ?" , name);
    }

    @Override
    public List<Patient> queryPatByNameList(String name) throws SQLException {
        return this.getBeanList("select id, docId, name, age, gender, diagnosis, bedNumber, admissionDate, adminId from hos.patient where docId = ? AND isRunHospital =0" , name);
    }

    public List<Patient> queryPatByNameAllList( ) throws SQLException {
        return this.getBeanList("select id, docId, name, age, gender, diagnosis, bedNumber, admissionDate, adminId from hos.patient where isRunHospital =0");
    }


    @Override
    public List<Patient> queryPat() throws SQLException {
        return this.getBeanList("select id, docId, name, age, gender, diagnosis, bedNumber, admissionDate, adminId from hos.patient WHERE isRunHospital =0 order by id asc");
    }

    @Override
    public List<Patient> queryPatTotal() throws SQLException {
        return this.getBeanList("select id, docId, name, age, gender, diagnosis, bedNumber, admissionDate, adminId from hos.patient order by id asc");
    }

    @Override
    public List<Patient> queryRoomNumber(String roomName) throws SQLException {
        return this.getBeanList("select id, docId, name, age, gender, diagnosis, bedNumber, admissionDate, adminId from hos.patient where bedNumber = ? AND isRunHospital =0" , roomName);
    }


}
